#!/usr/bin/env python
# -*- coding: gb2312 -*-

class bloodtest():
        kk = ''
        def __init__(self):
               kk = ''
        def par(self, per1, per2, chi = False):
                bld1 = bld2 = []
                if not chi: # have two parents
                        print 'given two parents'
                        print per1,per2
                        bld1 = bloodgene(per1)
                                                                
                else: # have one parent and the child
                        print 'given one parent and the child'
                        print per1,per2


def bloodgene(bd):
        rt = []
        rp = []
        if len(bd) == 3:
                rt = ['A','B']
        else:
                if bd.find('A')!=-1:
                        rt.append('A')
                if bd.find('B')!=-1:
                        rt.append('B')
                if len(rt) == 0:
                        rt = ['O','O']
                elif len(rt) ==1:
                        rt.append(['O', bd[0]])
        if bd.endswith('-'):
                rp = ['-','-']
        elif bd.endswith('+'):
                rp = ['+', ['-','+']]
        print 'blood '+bd+' has ' + repr(rt) + repr(rp)
        return (rt,rp)

def mate(bd1,bd2):
        posb = []
        for ab in bd1[0]:
                for ab2 in bd2[0]:
                        for rp in bd1[1]:                                
                                for rp2 in bd2[1]:
                                        gtyp = strlistadd(strlistadd(strlistadd(ab,ab2),rp),rp2)
                                        if isinstance(gtyp,list):
                                                for x in gtyp:
                                                        if not x in posb:
                                                                posb.append(x)
                                        else:
                                                if not gtyp in posb:
                                                        posb.append(gtyp)
        print posb
        
def strlistadd(s,l):
#        print 'adding '+repr(s)+' '+repr(l), 
        try:
                        
                if isinstance(s,list) and isinstance(l,list):
                        return [strlistadd(x,y) for x in s for y in l]
                try:
                       rt = s+l
                except TypeError:
                        rt  = []
                        if isinstance(s,str):
                                for y in l:
                                        rt.append(strlistadd(s,y))
                        else:
                                for x in s:
                                        rt.append(strlistadd(x,l))
                return rt
        finally:
#                print ' result is :' + repr(rt)
                pass
